package com.softline.documentsmall.controller;


import com.softline.documentsmall.entity.ApproveVO;
import com.softline.documentsmall.entity.DetailSubmitPageQueryVo;
import com.softline.documentsmall.entity.EntryDetailsSubmit;
import com.softline.documentsmall.ret.ReturnVO;
import com.softline.documentsmall.ret.ReturnVOUtils;
import com.softline.documentsmall.service.EntryDetailsSubmitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;

/**
 * @author zhongweicheng
 * @date 2020/8/25 10:11
 */
@Api(value="条目提交历史相关接口",tags={"条目提交历史相关接口"})
@RestController
@RequestMapping("/detailSubmit")
@CrossOrigin(allowCredentials = "true",allowedHeaders = "*")
public class EntryDetailSubmitController {

    @Autowired
    EntryDetailsSubmitService entryDetailsSubmitService;


    @ApiOperation(value="按照条件获取条目提交历史", notes = "按照条件获取条目提交历史")
    @GetMapping(value = "/getDetailSubmit")
    public ReturnVO getIssues(EntryDetailsSubmit entryDetailsSubmit){
        return entryDetailsSubmitService.findByParams(entryDetailsSubmit) ;
    }

    @ApiOperation(value="用户更新条目提交历史", notes = "用户更新条目提交历史,须传递id")
    @PostMapping(value = "/userUpdateDetailSubmit")
    public ReturnVO userUpdate(@RequestBody @Valid EntryDetailsSubmit entryDetailsSubmit){
        return entryDetailsSubmitService.userUpdateById(entryDetailsSubmit);
    }

    @ApiOperation(value="管理员更新条目提交历史", notes = "管理员更新条目提交历史,须传递id")
    @PostMapping(value = "/adminUpdateDetailSubmit")
    public ReturnVO adminUpdate(@RequestBody @Valid EntryDetailsSubmit entryDetailsSubmit){
        return entryDetailsSubmitService.adminUpdateById(entryDetailsSubmit);
    }

    @ApiOperation(value="新增条目提交历史", notes = "新增条目提交历史")
    @PostMapping(value = "/insertDetailSubmit")
    public ReturnVO insert(@RequestBody List<EntryDetailsSubmit> entryDetailsSubmits){

        return entryDetailsSubmitService.insertEntryDetailsSubmit(entryDetailsSubmits);
    }


    @ApiOperation(value="软删除条目提交历史", notes = "软删除条目提交历史")
    @PostMapping(value = "/softDeleteDetailSubmit")
    public ReturnVO softDelete(Integer id){
        return entryDetailsSubmitService.softDeleteById(id);
    }

    @ApiOperation(value="术语每个区块编辑/新增", notes = "术语每个区块编辑/新增")
    @PostMapping(value = "/editDictionaryBlock")
    public ReturnVO editDictionaryBlock(@RequestBody EntryDetailsSubmit submit){
        return ReturnVOUtils.success(entryDetailsSubmitService.editDictionaryBlock(submit));
    }

    @ApiOperation(value="管理员审批操作", notes = "管理员审批操作,须传递id")
    @PostMapping(value = "/adminApproveSubmit")
    public ReturnVO adminApproveSubmit(@RequestBody ApproveVO approveVO){
        return ReturnVOUtils.success(entryDetailsSubmitService.adminApproveSubmit(approveVO.getId(),approveVO.getApproveState(),approveVO.getUserName(),approveVO.getUserId(),approveVO.getReason()));
    }


    @ApiOperation(value="按照条件获取条目提交历史--分页(// 0 未审批，1通过，2不通过 3 不传)", notes = "按照条件获取条目提交历史--分页 (// 0 未审批，1通过，2不通过 3 不传)")
    @GetMapping(value = "/getDetailSubmitByPage")
    public ReturnVO getDetailSubmitByPage(DetailSubmitPageQueryVo pageQueryVo){
        return entryDetailsSubmitService.getDetailSubmitByPage(pageQueryVo) ;
    }
}
